package com.ftl;


//import freemarker.template.Configuration;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ftl {
    public static void main(String[] args)throws Exception {
//1.创建配置类
        //1.创建配置类
        Configuration configuration=new Configuration(Configuration.getVersion());
        //2.设置模板所在的目录
        configuration.setDirectoryForTemplateLoading(new File("G:\\dev\\IdeaProjects\\my_health\\MyExan\\src\\main\\java\\com\\ftl\\"));
//3.设置字符集
        configuration.setDefaultEncoding("utf-8");
//4.加载模板
        Template template = configuration.getTemplate("demo.ftl");
//5.创建数据模型
        Map map=new HashMap();
        map.put("name", "张三");
        map.put("message", "欢迎来到传智播客！");
//        map.put("data","我是我是我是");
        map.put("success",false);
//       遍历集合的数据
        List<Map<String,String>> list =new ArrayList<>();
            Map<String,String> map1 = new HashMap<>();
            map1.put("name","张三");
            map1.put("price","50");
            list.add(map1);
        Map<String,String> map2 = new HashMap<>();
        map2.put("name","张三1");
        map2.put("price","501");
        list.add(map2);
        Map<String,String> map3 = new HashMap<>();
        map3.put("name","张三2");
        map3.put("price","502");
        list.add(map3);
        map.put("goodsList",list);
//6.创建Writer对象
        Writer out =new FileWriter(new File("d:\\test.html"));
//7.输出
        template.process(map, out);
//8.关闭Writer对象
        out.close();
    }
}
